# 封装 类 接口对象层
import requests


class EmpMangerApi(object):
    # 添加员工
    def add_emp(self, req_head, req_body):
        resp = requests.post(url="http://ihrm2-test.itheima.net/api/sys/user/",
                             headers=req_head, json=req_body)

        return resp

    # 查询
    def query_emp(self, emp_id, req_head):
        resp = requests.get(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id,
                            headers=req_head)

        return resp

    # 修改员工
    def modify_emp(self, emp_id, req_head, req_body):
        resp = requests.put(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id,
                            headers=req_head, json=req_body)
        return resp

    # 删除员工
    def del_emp(self, emp_id, req_head):
        resp = requests.delete(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id,
                               headers=req_head)

        return resp


if __name__ == '__main__':
    # 添加
    emp = EmpMangerApi()
    req_head = {"Authorization": "15600f9a-bd44-40ff-ba81-091110104988"}
    req_body = {
        "username": "jack123",
        "mobile": "13858577226",
        "workNumber": "666"
    }
    resp = emp.add_emp(req_head, req_body)
    print(resp.json())

    # 修改
    # emp = EmpMangerApi()
    # req_head = {"Authorization": "15600f9a-bd44-40ff-ba81-091110104988"}
    # emp_id = "1570675092826894336"
    # req_body1 = {"username": "江东铁壁"}
    # resp = emp.modify_emp(emp_id, req_head, req_body1)
    # print(resp.json())

    # 查询
    # emp = EmpMangerApi()
    # emp_id = "1570675092826894336"
    # req_head = {"Authorization": "15600f9a-bd44-40ff-ba81-091110104988"}
    # resp = emp.query_emp(emp_id, req_head)
    # print(resp.json())

    # 删除
    # emp = EmpMangerApi()
    # emp_id = "1570675092826894336"
    # req_head = {"Authorization": "15600f9a-bd44-40ff-ba81-091110104988"}
    # resp = emp.del_emp(emp_id, req_head)
    # print(resp.json())
